#ifndef SLIPPYMAP_H
#define SLIPPYMAP_H

#include <QtCore>
#include <QtGui>
#include <QtNetwork>
#include <QDebug>

#include <math.h>


class SlippyMap: public QObject
{
    Q_OBJECT

private:
    QPoint m_offset;
    QRect m_tilesRect;
    QPixmap m_emptyTile;
    QHash<QPoint, QPixmap> m_tilePixmaps;
    QNetworkAccessManager m_manager;
    QUrl m_url;
    QNetworkCacheMetaData *metaData;

public:
    QNetworkDiskCache *cache;
    int width;
    int height;
    int zoom;
    qreal latitude;
    qreal longitude;
    SlippyMap(QObject *parent = 0);
    void invalidate();
    void render(QPainter *p, const QRect &rect);
    void pan(const QPoint &delta);

private slots:
    void handleNetworkData(QNetworkReply *reply);
    void download();

signals:
    void updated(const QRect &rect);

protected:
    QRect tileRect(const QPoint &tp);

};


#endif // SLIPPYMAP_H
